<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>请选择客户</title>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>
<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="FXBR">
                    <div class="fieldBox">
                        <div class="label">客户名称</div>
                        <div class="field">
                            <input name="cstNm" id="cstNm" type="text" class="ui-textbox" value="" ligerui="width: 160">
                        </div>
                    </div>
                    <div class="fieldBox">
                        <div class="label">证件号码</div>
                        <div class="field">
                            <input name="cstIdcard" id="cstIdcard" type="text" class="ui-textbox" value="" ligerui="width: 160">
                        </div>
                    </div>
                    <div class="fieldBox">
                        <div class="label">风险来源</div>
                        <div class="field">
                            <select name="signSource" id="signSource">
                                <option selected value="">请选择</option>
                                <c:forEach items="${signSourceList}" var="source">
                                    <c:if test="${signSource == source.key }">
                                        <option value="${source.key }" selected>${source.value }</option>
                                    </c:if>
                                    <c:if test="${signSource != source.key }">
                                        <option value="${source.key}">${source.value}</option>
                                    </c:if>
                                </c:forEach>
                            </select>
                        </div>
                    </div>
                </div>

                <div class="clearFix"></div>
                <div class="btnsBox formBtns notRight">
                    <span id="searchBtn" class="sq-button-round">查询</span>
                    <span id="clearBtn" class="sq-button-round">清空</span>
                    <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                    <span id="chooseBtn" class="sq-button-round" onclick="chooseBtn();">确定</span>
                </div>
            </div>
        </form>
    </div>
</div>
<div id="ligergrid1" class="sq-grid"></div>
</div>

<script type="text/javascript">
    var grid = null;
    $(function () {
        initForm();
        initGrid();//注意初始化要在initForm之后,因为在初始化grid的时候需要form参数
        searchBtnEvent();
        clearBtnEvent();
    });

    //清空按钮事件
    function clearBtnEvent() {
        $("#clearBtn").click(function (event) {
            $("#resetBtn").click();  //重置 input-text
            var form = liger.get("searchBar");
            form.setData({  //重置select等特殊表单
                "signSource": ""
            });
        });
    }

    //初始化表单
    function initForm() {
        $("#searchBar").ligerForm();
    }

    //查询按钮事件
    function searchBtnEvent() {
        $("#searchBtn").click(function (event) {
            var form = new liger.get("searchBar");
            var data = form.getData();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            ;
            grid.reload();
        });
    }

    //查询参数
    function getSearchParams() {
        var form = new liger.get("searchBar");
        var data = form.getData();
        return data;
    }

    //初始化列表
    function initGrid() {
        $("#ligergrid1").ligerGrid({
            url: '<%=path%>/risk/rskCstSignLog/initCstList.do',
            method: 'get',
            parms: getSearchParams(),
            columns: [
                {display: '客户名称', name: 'cstNm', width: 180, align: 'center', enabledSort: true},
                {display: '证件号码', name: 'cstIdcard', width: 180, align: 'center', enabledSort: true},
                {display: '风险来源', name: 'signSourceNm', width: 180, align: 'center', enabledSort: true},
                {display: '风险标记', name: 'signResTypeNm', width: 120, align: 'center', enabledSort: true},
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            checkbox: true,
            rownumbers: true
        });
        grid = liger.get("ligergrid1");
        grid.setHeight(100);
        grid.options.isSingleCheck = true;
    }

    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
        }
        return dateStr;
    }

    /*//查看数据
    function showDetail(_id, _cstTypCd) {
        //1 自然人  2 法人
        if (_cstTypCd == 1) {
            Add_navTab('tab_customer_np_detail' + _id, '客户详情', '<%=path%>/customer/cstbscinfo/toCustCstBacInfoNpDetailPage.do?id=' + _id);
        } else if (_cstTypCd == 2) {
            Add_navTab('tab_customer_corp_detail' + _id, '客户详情', '<%=path%>/customer/cstbscinfo/toCustCstBacInfoCorpDetailPage.do?id=' + _id);
        }
    }*/

    //新增数据,先选择客户类型,然后做好验证后在进入具体的页面
    function chooseBtn() {
        var selectedRows = grid.getSelectedRows();
        if (selectedRows.length != 1) {
            $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
            return;
        }
        if (selectedRows == '') {
            alert("必须选择一条客户数据");
        } else if (selectedRows.length != 1) {
            alert("只能选择一条客户数据");
        } else {
            var cstId = selectedRows[0].cstId;
            var cstNm = selectedRows[0].cstNm;
            var cstIdcard = '';
            if(selectedRows[0].cstIdcard != null){
                cstIdcard = selectedRows[0].cstIdcard;
            }
            var signSource = selectedRows[0].signSource;
            var url = '<%=path%>/risk/rskCstSignLog/toAddPage.do?cstId=' + cstId + '&cstNm=' + cstNm + '&signSource=' + signSource + '&cstIdcard=' + cstIdcard;
            var title = '新增客户风险标记';
            var str = '是否确认新增该客户风险标记?';
            if(selectedRows[0].id != null && selectedRows[0].id != ''){
                $.ligerDialog.SQalert({content: "该客户已风险标记,不可新增!", SQ_type: "warning"});
                return;
            }
            $.ligerDialog.confirm(str, function (flag) {
                if(flag == false) {
                    return;
                }else{
                    $.ligerDialog.open({
                        width: 1000,
                        height: 500,
                        title: title,
                        url: url
                    });
                }
            });
        }
    }

    function iframeResize() {
        if (parent.mainApp) {
            parent.mainApp.parentTab.onResize();
        }
        ;
    }
</script>

</body>
</html>